export function nameFilters(name) {  //对名字进行过滤    张三（*三）  张某某（张*某）
 
  if (typeof(name) == "undefined") {
 
    return name;
 
  } else if (name.length < 2) {
 
    return name;
 
  } else if (name.length === 2) {
 
    return new Array(name.length).join("*") + name.substr(-1);
 
  } else {
 
    return (
 
      name.substr(0, 1) + new Array(name.length - 1).join("*") + name.substr(-1)
 
    );
 
  }
 
}
 
 
export function idCardFilters(num) {   //身份证进行过滤  429004199902024125（42900419********25）
 
  if (typeof(num) == "undefined") {
 
    return num;
 
  } else if (num.length != 18) {
 
    return num;
 
  } else {
 
    return num.replace(/(\d{8})\d{8}(\d*)/, "$1********$2");
 
  }
 
}
 
 
export function sexIdcareFilter(num) {   //根据身份证判断性别
 
  if (typeof(num) == "undefined") {
 
    return num;
 
  } else if (num.length != 18) {
 
    return num;
 
  } else {
 
    return num.substr(16, 1) % 2 === 1 ? "男" : "女";
 
  }
 
}
 
 
export function phoneFilters(num) {   //手机号码进行过滤  18641526389  （186****6389）
 
  if (typeof(num) == "undefined") {
 
    return num;
 
  } else if (num.length != 11) {
 
    return num;
 
  } else {
 
    return num.replace(/(\d{3})\d{4}(\d*)/, "$1****$2");
 
  }
 
}
 
 
export function textFilter(type, n) {   //文本超出后截取
 
    if (typeof(type) == 'undefined' || type.length <= n) {
 
        return type
 
    } else {
 
       if (type.length > n) {
 
           return type.substr(0, n) + '...'
 
        }
 
    }
 
}
 
 
 
export function priceFilter(type, n) {    //保留两位小数
 
	if (typeof(type) == 'undefined') {
 
		return type
 
	} else {
 
		return "￥" + type.toFixed(n)
 
   }
 
}
 
 
 
export function timeFilters(type) {   //时间
 
      var time = new Date(type);
 
      var year = time.getFullYear(); //年
 
      var month = (time.getMonth() + 1 + "").padStart(2, "0"); //月
 
      var date = (time.getDate() + "").padStart(2, "0"); //日
 
      var hour = (time.getHours() + "").padStart(2, "0"); //时
 
      var minutes = (time.getMinutes() + "").padStart(2, "0"); //分
 
      var seconds = (time.getSeconds() + "").padStart(2, "0"); //秒
 
      return `${year}-${month}-${date} ${hour}:${minutes}:${seconds}`;
 
}